package array;

import java.util.Scanner;

class Harry {
	public int[] a = new int[10];//could not double the size when entering 11th element
	public int SIZE = a.length;
	
	public void add(int b){//SIZE==size() ?
		if (SIZE==size()){
			//array is full 
			int[] c = new int[SIZE*2];
			for(int i = 0 ;i<SIZE;i++){
				c[i]=a[i];
			}
			a=c;
			SIZE=c.length;
		}
		for(int i = 0;i<SIZE;i++){
			if (a[i]==0){
				a[i]=b;
				break;
			}
		}
		}
	public boolean remove(int b){//modify
		for(int i = 0;i<SIZE;i++){
			if(a[i]==b){
				a[i]=0;
				for (int j=i;j<SIZE;j++){
					a[i]=a[i+1];
				}
				return true;

			}
		}
		return false;
		
	}
	public int size(){
		int count =0;
		for(int i = 0;i<SIZE;i++){
			if(a[i]!=0){
				count++;
			}
		}
		return count;

		}
	public void clear(){
		for(int i = 0;i<SIZE;i++){
			a[i]=0;
		}
	}
	}

public class MyArrayList{
	public static void main(String[] args) {
		Harry a = new Harry();
		
		a.add(5);
		a.add(6);
		a.add(7);
		a.add(8);
		a.add(9);
		a.add(10);//is not filling element if adding "0"
		a.add(1);
		a.add(2);
		a.add(3);
		a.add(4);
		
		System.out.println(a.remove(8));
		System.out.println(a.remove(80));

		for(int i = 0;i<10;i++){
			System.out.println("a["+i+"]    "+a.a[i]);

		}
		System.out.println();
		System.out.println("After removing one element >> size :  "+a.size());
		a.clear();
		System.out.println("After removing all elements >> size :  "+a.size());
	}
}
